package com.gwcloud.leetcode.tags.array;

/** 
* @ClassName   : Leetcode1343 
* @author      : ganwei 
* @date        : 2020年6月14日 
* @Description : TODO 
*/
public class Leetcode1343 {
	/**
	 * -解题思路，滑动窗口
	 */
    public int numOfSubarrays(int[] arr, int k, int threshold) {
    	if(arr.length < k) {
    		return 0;
    	}
    	int sum = 0;
    	int count = 0;
    	for(int i = 0; i < arr.length; i++) {
    		if(i < k) {
    			sum += arr[i];
    		}else {
    			sum -= arr[i-k];
    			sum += arr[i];
    		}
    		if(i >= k-1 && sum/k >=  threshold) {
    			count++;
    		}

    	}
    	return count;
    }
    
    public static void main(String[] args) {
    	Leetcode1343 l1343 = new Leetcode1343();
    	int[] arr = {11,13,17,23,29,31,7,5,2,3};
    	System.out.println(l1343.numOfSubarrays(arr, 3, 5));
    }
}
